﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using StudentsManager.Models;

namespace StudentsManager.Forms
{
    public partial class StudentForm : Form
    {
        public Student QueryStudent { get; set; }

        public StudentForm()
        {
            InitializeComponent();
        }

        public StudentForm(Student student)
        {
            InitializeComponent();
            txtStudentName.Text = student.Name;
            numericUpDownAge.Value = student.Age;
            if (student.Gender == 0)
            {
                femaleRadioButton.Checked = true;
            }
            else if (student.Gender == 1)
            {
                maleRadioButton.Checked = true;
            }
            txtClassName.Text = student.ClassName;
            txtSchoolName.Text = student.SchoolName;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            int gender = -1;
            if (femaleRadioButton.Checked)
                gender = 0;
            else if (maleRadioButton.Checked)
                gender = 1;

                QueryStudent = new Student
            {
                Name = txtStudentName.Text,
                Age = (int)numericUpDownAge.Value,
                Gender = gender,
                ClassName = txtClassName.Text,
                SchoolName = txtSchoolName.Text
            };
            DialogResult = DialogResult.OK;
            Close();
        }
    }
}
